package com.turato.observer.clean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tuhao
 * @date 2021/2/9 5:02 下午
 * @desc 用户注册事件主题
 */
public class UserRegisterSubject {

    private final List<UserRegisterObserver> observers;

    public void addObserver(UserRegisterObserver obs) {
        observers.add(obs);
    }

    public void removeObserver(UserRegisterObserver obs) {
        observers.remove(obs);
    }

    public UserRegisterSubject() {
        observers = new ArrayList<UserRegisterObserver>();
    }

    public void createUserRegisterEvent(RegisterEvent event) {
        notifyObservers(event);
    }

    private void notifyObservers(RegisterEvent event) {
        for (UserRegisterObserver obs : observers) {
            obs.update(event);
        }
    }

}
